#!/bin/sh
# PCP QA Test No. 1594
# Do the demo programs we ship actually work?
#
# Copyright (c) 2025 Ken McDonell.  All Rights Reserved.
#

if [ $# -eq 0 ]
then
    seq=`basename $0`
    echo "QA output created by $seq"
else
    # use $seq from caller, unless not set
    [ -n "$seq" ] || seq=`basename $0`
    echo "QA output created by `basename $0` $*"
fi

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

do_valgrind=false
if [ "$1" = "--valgrind" ]
then
    _check_valgrind
    do_valgrind=true
fi

_cleanup()
{
    cd $here
    $sudo rm -rf $tmp $tmp.*
}

status=1	# failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

_filter()
{
    sed \
	-e "s@$tmp@TMP@g" \
    # end
}

# real QA test starts here
mkdir $tmp || exit
cp -r $PCP_DEMOS_DIR/* $tmp || exit
cd $tmp

for dir in *
do
    [ -d "$dir" ] || continue
    echo
    echo "=== $dir ==="
    cd $dir
    if ! [ -f Makefile ]
    then
	echo "Warning: no Makefile"
    else
	if ! $PCP_MAKE_PROG clean >$tmp.out 2>&1
	then
	    cat $tmp.out
	    echo "make clean failed!"
	fi
	if ! $PCP_MAKE_PROG >$tmp.out 2>&1
	then
	    cat $tmp.out
	    echo "make clean failed!"
	fi
    fi
    cd ..
done

# success, all done
status=0
exit
